package com.oceansoft.core.jxkh.service.impl;

import com.hui.platform.system.exception.HuiException;
import com.oceansoft.core.common.util.Pagination;
import com.oceansoft.core.domain.SysUser;
import com.oceansoft.core.jxkh.dao.ISigninDao;
import com.oceansoft.core.jxkh.dao.IWorkLogDao;
import com.oceansoft.core.jxkh.domain.Daliywork;
import com.oceansoft.core.jxkh.domain.Signin;
import com.oceansoft.core.jxkh.domain.WorkLog;
import com.oceansoft.core.jxkh.service.ISigninService;
import com.oceansoft.core.jxkh.service.IWorkLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2017/10/24.
 */
@Service
public class SigninServiceImpl implements ISigninService {

    @Resource
    private ISigninDao signinDao;

    @Override
    public String signIn(String policeNum) throws HuiException {
        //验证当前账号今日是否签到
        int i = signinDao.countSignToday(policeNum);
        if(i>0){
            signinDao.signOut(policeNum);
        }else{
            signinDao.signIn(policeNum);
        }
        return signinDao.getNowTime();
    }

    @Override
    public int checkIsSign(String policeNum) throws HuiException {
        int result=0;//未签到
        //验证当前账号今日是否签到
        int i = signinDao.countSignToday(policeNum);
        if(i>0){
            //今日是否已经签退
            int k = signinDao.countSignOutToday(policeNum);
            if(k>0){//已经签退
                result=2;
            }else{//已签到
                result=1;
            }
        }
        return result;
    }

    @Override
    public Signin findByPoliceNum(String policeNum) {
        return signinDao.findByPoliceNum(policeNum);
    }

    @Override
    public Signin findByPoliceNumAndDate(String policeNum, String workdate) {
        return signinDao.findByPoliceNumAndDate(policeNum,workdate);
    }
}
